
* data	
use "data/inputs/PrecinctData.dta", clear


* normalize
egen mesascount = count(chavista), by(year)
sort year nonmiss_twoprevyears
by year: gen n = _n 
gen pctile = n / mesascount


* density graph for appendix
#delimit;
twoway	(kdensity nonmiss_twoprevyears  if year == 1998 & pctile >= 0.001 & pctile <= 0.999, 
		 lcolor(blue))
		(kdensity nonmiss_twoprevyears  if year == 2000 & pctile >= 0.001 & pctile <= 0.999, 
		 lcolor(blue%50) lpattern(dash))
		(kdensity nonmiss_twoprevyears  if year == 2006 & pctile >= 0.001 & pctile <= 0.999, 
		 lcolor(black%50))
	    (kdensity nonmiss_twoprevyears  if year == 2012 & pctile >= 0.001 & pctile <= 0.999, 
		 lcolor(black) lpattern(dash) lwidth(vthin)),
		graphregion(fcolor(white) lcolor(white) margin(zero))
        plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none))
        xsize(11) ysize(5)
		title("", size(large))
		ytitle("Density", color(black) size(large))
		xtitle("Proportion of Voters with Formal Employment", size(large))
        yscale()
		ylabel(, labsize(large) glcolor(white) angle(horizontal))
		xlabel(, labsize(large))
		legend(order(1 "1998" 2 "2000" 3 "2006" 4 "2012")	 cols(1) pos(2) ring(0)
		region(lcolor(white)));
graph export "figures/FigureD3a.pdf", replace;
#delimit cr


* gradient graph for appendix
#delimit;
twoway  (lpolyci chavista nonmiss_twoprevyears if year == 1998 & pctile >= 0.001 & pctile <= 0.999, 
	     lcolor(blue%50) lwidth(vthin) ciplot(rline) degree(1))
		 
		(lpoly chavista nonmiss_twoprevyears if year == 1998 & pctile >= 0.001 & pctile <= 0.999,
		lcolor(blue) degree(1))
				
		(lpolyci chavista nonmiss_twoprevyears if year == 2000 & pctile >= 0.001 & pctile <= 0.999, 
	     lcolor(blue%30) lwidth(vthin) ciplot(rline) degree(1))
		
		(lpoly chavista nonmiss_twoprevyears if year == 2000 & pctile >= 0.001 & pctile <= 0.999, 
		lcolor(blue%70) lpattern(dash)  degree(1))
		
		(lpolyci chavista nonmiss_twoprevyears if year == 2006 & pctile >= 0.001 & pctile <= 0.999, 
	     lcolor(black%30) lwidth(vthin) ciplot(rline) degree(1))
		
		(lpoly chavista nonmiss_twoprevyears if year == 2006 & pctile >= 0.001 & pctile <= 0.999, 
		lcolor(black%50) degree(1))
	    
		(lpolyci chavista nonmiss_twoprevyears if year == 2012 & pctile >= 0.001 & pctile <= 0.999, 
	     lcolor(black%50) lwidth(vthin) ciplot(rline) degree(1))
		
		(lpoly chavista nonmiss_twoprevyears if year == 2012 & pctile >= 0.001 & pctile <= 0.999, 
		lcolor(black) lpattern(dash)  degree(1)),

		graphregion(fcolor(white) lcolor(white) margin(zero))
        plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none))
        xsize(11) ysize(5)
		title("", size(large))
		ytitle("Chávez Vote Share", color(black) size(large))
		xtitle("Fraction of Voters with Formal Employment", size(large))
        yscale()
		xscale()
		ylabel(.3(.1).9, labsize(large) glcolor(white) angle(horizontal))
		xlabel(, labsize(large))
		legend(order(3 "1998" 6 "2000" 9 "2006" 12 "2012")	 cols(1) pos(2) ring(0)
		region(lcolor(white)));
graph export "figures/FigureD3b.pdf", replace;


* End
